home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / rexxutil.zip / RXLIBMGR.CMD < prev   
OS/2 REXX Batch file  |  1990-10-02  |  11KB  |  309 lines

  1. /** REXX **************************************************************/
  2. /*                                                                    */
  3. /*  Function Name:  RXLIBMGR                                          */
  4. /*                                                                    */
  5. /*  Description:    Maintains Rexx Macrospace libraries.              */
  6. /*                                                                    */
  7. /*  Author:         W. David Ashley                                   */
  8. /*                                                                    */
  9. /*  Version:        1.0                                               */
  10. /*                                                                    */
  11. /*                                                                    */
  12. /**********************************************************************/
  13.  
  14. /* Check for correct number of input arguments */
  15. if arg() \= 1 then do
  16.    say 'Error: Incorrect input arguments.'
  17.    say
  18.    say 'Syntax: REXMACRO [d:[path]]filename.ext'
  19.    exit
  20.    end
  21. if length(arg(1)) < 3 then do
  22.    say 'Error: Incorrect input arguments.'
  23.    say
  24.    say 'Syntax: REXMACRO [d:[path]]filename.ext'
  25.    exit
  26.    end
  27. arg file
  28.  
  29. /* Make REXXUTIL.DLL library functions available */
  30. if rxfuncquery('RexMacroLoad') = 1 then ,
  31.  call rxfuncadd 'RexMacroLoad', 'REXXUTIL', 'RexMacroLoad'
  32. if rxfuncquery('RexMacroSave') = 1 then ,
  33.  call rxfuncadd 'RexMacroSave', 'REXXUTIL', 'RexMacroSave'
  34. if rxfuncquery('RexMacroErase') = 1 then ,
  35.  call rxfuncadd 'RexMacroErase', 'REXXUTIL', 'RexMacroErase'
  36. if rxfuncquery('RexMacroQuery') = 1 then ,
  37.  call rxfuncadd 'RexMacroQuery', 'REXXUTIL', 'RexMacroQuery'
  38. if rxfuncquery('RexMacroDrop') = 1 then ,
  39.  call rxfuncadd 'RexMacroDrop', 'REXXUTIL', 'RexMacroDrop'
  40. if rxfuncquery('RexMacroReOrder') = 1 then ,
  41.  call rxfuncadd 'RexMacroReOrder', 'REXXUTIL', 'RexMacroReOrder'
  42. if rxfuncquery('RexRead') = 1 then ,
  43.  call rxfuncadd 'RexRead', 'REXXUTIL', 'RexRead'
  44. if rxfuncquery('RexDelete') = 1 then ,
  45.  call rxfuncadd 'RexDelete', 'REXXUTIL', 'RexDelete'
  46.  
  47. /* Read input file */
  48. retc = RexRead(file, 'fline')
  49. if retc \= 0 then do
  50.    select
  51.       when retc = 1 then do
  52.          say 'Error: Cannot open input file' file'.'
  53.          exit
  54.          end
  55.       when retc = 2 then do
  56.          say 'Error: Out of memory or memory error.'
  57.          exit
  58.          end
  59.       when retc = 5 then do
  60.          say 'Error: Internal REXXUTIL error. Contact REXXUTIL programmer.'
  61.          exit
  62.          end
  63.       otherwise do
  64.          say 'Error: Unknown error. Contact REXXUTIL programmer.'
  65.          exit
  66.          end
  67.       end
  68.    end
  69. if fline.0 = 0 then do
  70.    say 'Error: Input file is empty.'
  71.    exit
  72.    end
  73.  
  74. /* Save the current Rexx macrospace */
  75. retc = RexMacroSave('temp.rxl')
  76. if retc > 0 then do
  77.    temp_saved = 'NO'
  78.    if retc > 2 then do
  79.       say 'Error: Could not save current Macrospace.'
  80.       exit
  81.       end
  82.    end
  83. else temp_saved = 'YES'
  84. call RexMacroErase
  85.  
  86. /* We are now ready to process the input file */
  87. cmd = ''
  88. parm1 = ''
  89. parm2 = ''
  90. parm3 = ''
  91. do i = 1 to fline.0
  92.    /* Process a line of the input file */
  93.    parse upper value fline.i with cmd parm1 parm2 parm3
  94.    select
  95.       when cmd = 'LOAD' then    call loadfile parm1, parm2, parm3
  96.       when cmd = 'DROP' then    call dropfunc parm1
  97.       when cmd = 'REORDER' then call reorder parm1, parm2
  98.       when cmd = 'SAVE' then    call savefile parm1
  99.       otherwise do
  100.         say 'Error: Invalid command in input file' file'.'
  101.         call Reload
  102.         exit
  103.         end
  104.       end
  105.    end
  106.  
  107. /* reset Rexx macrospace to original form */
  108. call Reload
  109.  
  110. /* exit function */
  111. return
  112.  
  113. /**********************************************************************/
  114. /*                                                                    */
  115. /*  Function Name:  Loadfile()                                        */
  116. /*                                                                    */
  117. /*  Description:    Load a Rexx Macrospace library into the Macrospace*/
  118. /*                                                                    */
  119. /**********************************************************************/
  120.  
  121. Loadfile: procedure expose i
  122.  
  123.    if arg() = 3 then do
  124.       retc = RexMacroLoad(arg(1), arg(2), arg(3))
  125.       end
  126.    else if arg() = 1 then do
  127.       retc = RexMacroLoad(arg(1))
  128.       end
  129.    else do
  130.       say 'Error: Line 'i' of input file.'
  131.       say '  Incorrect number of arguments to function Loadfile().'
  132.       call Reload
  133.       exit
  134.       end
  135.    select
  136.       when retc = 0 then do
  137.          if arg() = 3 then,
  138.           say 'Function 'arg(2)' successfully loaded to macrospace.'
  139.          else,
  140.           say 'Library 'arg(1)' successfully loaded to macrospace.'
  141.          end
  142.       when retc = 1 then do
  143.          say 'Error: Line 'i' of input file.'
  144.          say '  No Macro storage space available.'
  145.          call Reload
  146.          exit
  147.          end
  148.       when retc = 2 then do
  149.          say 'Warning: Line 'i' of input file.'
  150.          say '  Function not found.'
  151.          end
  152.       when retc = 4 then do
  153.          say 'Warning: Line 'i' of input file.'
  154.          say '  Function(s) already exist in macrospace.'
  155.          say '  Function(s) not loaded to macrospace.'
  156.          end
  157.       when retc = 5 then do
  158.          say 'Error: Line 'i' of input file.'
  159.          say '  Macro file error.'
  160.          call Reload
  161.          exit
  162.          end
  163.       when retc = 6 then do
  164.          say 'Error: Line 'i' of input file.'
  165.          say '  Macro library file signature error.'
  166.          call Reload
  167.          exit
  168.          end
  169.       when retc = 7 then do
  170.          say 'Error: Line 'i' of input file.'
  171.          say '  Function source not found.'
  172.          call Reload
  173.          exit
  174.          end
  175.       when retc = 8 then do
  176.          say 'Error: Line 'i' of input file.'
  177.          say '  Invalid search position.'
  178.          call Reload
  179.          exit
  180.          end
  181.       otherwise do
  182.          say 'Error: Line 'i' of input file.'
  183.          say '  Unknown error. Contact REXXUTIL programmer.'
  184.          call Reload
  185.          exit
  186.          end
  187.       end
  188.    return
  189.    end
  190.  
  191. /**********************************************************************/
  192. /*                                                                    */
  193. /*  Function Name:  Savefile()                                        */
  194. /*                                                                    */
  195. /*  Description:    Save a Rexx Macrospace to a file                  */
  196. /*                                                                    */
  197. /**********************************************************************/
  198.  
  199. Savefile: procedure expose i
  200.  
  201.    retc = RexMacroSave(arg(1))
  202.    select
  203.       when retc = 0 then do
  204.          say 'Macrospace saved to library file' arg(1)'.'
  205.          end
  206.       when retc = 2 then do
  207.          say 'Warning: Line 'i' of input file.'
  208.          say '  Macro function(s) not found.'
  209.          end
  210.       when retc = 3 then do
  211.          say 'Warning: Line 'i' of input file.'
  212.          say '  Extension required on Macro Library filename.'
  213.          say '  Macrospace not saved.'
  214.          end
  215.       when retc = 5 then do
  216.          say 'Error: Line 'i' of input file.'
  217.          say '  Macro file error.'
  218.          call Reload
  219.          exit
  220.          end
  221.       otherwise do
  222.          say 'Error: Line 'i' of input file.'
  223.          say '  Unknown error. Contact REXXUTIL programmer.'
  224.          call Reload
  225.          exit
  226.          end
  227.       end
  228.    return
  229.    end
  230.  
  231. /**********************************************************************/
  232. /*                                                                    */
  233. /*  Function Name:  Dropfunc()                                        */
  234. /*                                                                    */
  235. /*  Description:    Drop a function from the Rexx macrospace          */
  236. /*                                                                    */
  237. /**********************************************************************/
  238.  
  239. Dropfunc: procedure expose i
  240.  
  241.    retc = RexMacroDrop(arg(1))
  242.    select
  243.       when retc = 0 then do
  244.          say 'Function' funcname 'successfully dropped.'
  245.          end
  246.       when retc = 2 then do
  247.          say 'Warning: Line 'i' of input file.'
  248.          say '  Macro function(s) not found.'
  249.          end
  250.       otherwise do
  251.          say 'Error: Line 'i' of input file.'
  252.          say '  Unknown error. Contact REXXUTIL programmer.'
  253.          call Reload
  254.          exit
  255.          end
  256.       end
  257.    return
  258.    end
  259.  
  260. /**********************************************************************/
  261. /*                                                                    */
  262. /*  Function Name:  Reorder()                                         */
  263. /*                                                                    */
  264. /*  Description:    Reorder macrospace function                       */
  265. /*                                                                    */
  266. /**********************************************************************/
  267.  
  268. Reorder: procedure expose i
  269.  
  270.    retc = RexMacroReOrder(arg(1), arg(2))
  271.    select
  272.       when retc = 0 then do
  273.          say 'Function' arg(1) 'successfully reorderd.'
  274.          end
  275.       when retc = 2 then do
  276.          say 'Warning: Line 'i' of input file.'
  277.          say '  Macro function(s) not found.'
  278.          end
  279.       when retc = 8 then do
  280.          say 'Error: Line 'i' of input file.'
  281.          say '  Invalid search position.'
  282.          call Reload
  283.          exit
  284.          end
  285.       otherwise do
  286.          say 'Error: Line 'i' of input file.'
  287.          say '  Unknown error. Contact REXXUTIL programmer.'
  288.          call Reload
  289.          exit
  290.          end
  291.       end
  292.    return
  293.    end
  294.  
  295. /**********************************************************************/
  296. /*                                                                    */
  297. /*  Function Name:  Reload()                                          */
  298. /*                                                                    */
  299. /*  Description:    Reload macrospace from temporary file.            */
  300. /*                                                                    */
  301. /**********************************************************************/
  302.  
  303. Reload: procedure expose temp_saved
  304.    call RexMacroErase
  305.    if temp_saved = 'YES' then call RexMacroLoad 'temp.rxl'
  306.    call RexDelete 'temp.rxl'
  307.    return
  308.    end
  309.